package com.dubito.composenote.data

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.dubito.composenote.model.Note
import kotlinx.coroutines.flow.Flow

/**
 * author: LiLiang
 * createTime: 2022/10/6-11:37
 * remark:
 **/
@Dao
interface NotesDao {

    /**
     * 根据ID查找
     */
    @Query("select * from notes where notes.id = :id")
    suspend fun getNoteById(id: Int): Note?

    @Query("select * from notes order by dateUpdated desc")
    fun getNotes(): Flow<List<Note>>

    @Delete
    suspend fun deleteNote(note: Note)

    @Update
    suspend fun updateNote(note: Note)

    @Insert
    suspend fun insertNote(note: Note)
}